// Model
function search_questions($search_term)
{
global $conn;
$sql = "??? Id, Question, Date from Questions ??? Question like '%" . $search_term . "%'";
$result = ???($conn, $sql);
$str = '[';
$first = true;
while($row = ???($result)) {
if ($first) $first = false;
else $str .= ',';
// $str .= '{"Question":"' . $row['Question'] . '", "Date":"' . $row['Date'] . '"}'; // {"Question" => "...", "Date" => "..."}
$str .= ???($row); // json_???
}
$str .= ']';
return $str;
}
// Controller
echo search_questions($t);
/* or
* It is more desirable.
*/
// Model
function search_questions($search_term)
{
global $conn;
$sql = "??? Id, Question, Date from Questions ??? Question like '%" . $search_term . "%'";
$result = ???($conn, $sql);
$data = array(); // []
$i = 0;
while($row = ???($result))
$data[$i++] = $row; // $row: an associative array
return $data;
}
// Controller
echo ???(search_questions($t)); // Convert the array to a JSON string and send
// In general, you should not include MainPage or StartPage